package com.fg.cloud.manager.service.agency.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.fg.cloud.manager.entry.BaseEntity;
import com.fg.cloud.manager.entry.agency.vo.AgencyInfoCompanyVo;
import com.fg.cloud.manager.entry.agency.vo.AgencyInfoVo;
import com.fg.cloud.manager.mapper.BaseMapper;
import com.fg.cloud.manager.mapper.agency.AgencyAccountMapper;
import com.fg.cloud.manager.mapper.agency.AgencyAddressMapper;
import com.fg.cloud.manager.mapper.agency.AgencyInfoMapper;
import com.fg.cloud.manager.mapper.agency.AgencyUserMapper;
import com.fg.cloud.manager.service.BaseServiceImpl;
import com.fg.cloud.manager.service.agency.AgencyInfoService;

@Service
public class AgencyInfoServiceImpl extends BaseServiceImpl implements AgencyInfoService {
	
	@Autowired
	private AgencyInfoMapper agencyInfoMapper;
	@Autowired
	private AgencyAddressMapper agencyAddressMapper;	
	@Autowired
	private AgencyUserMapper agencyUserMapper;
	@Autowired
	private AgencyAccountMapper agencyAccountMapper;
	
	
	@Override
	protected <T extends BaseEntity> BaseMapper getBaseMapper() {
		return agencyInfoMapper;
	}
	
	/**
	 * 经销商数据重置
	 */
	@Override
	public boolean deleteAgency(Long facId) {
		//1.删除经销商收货地址
		long r1 = agencyAddressMapper.delByfacId(facId);
		//2.删除经销商账户
		long r2 = agencyAccountMapper.delByfacId(facId);
		//3.删除经销商用户
		long r3 = agencyUserMapper.delByfacId(facId);
		//4.删除经销商图片
		long r4 = agencyInfoMapper.delAgencyImg(facId);
		//5.删除经销商购物车
		long r5 = agencyInfoMapper.delAgencyCart(facId);
		//6.删除经销商收藏夹
		long r6 = agencyInfoMapper.delAgencyFav(facId);
		//7.删除经销商信息
		long r7 = agencyInfoMapper.delByfacId(facId);
		
		if ( r1>0 && r2>0 && r3>0 && r4>0 && r5>0 && r6>0 && r7>0 ) return true;

		return false;
	}
	
	/**
	 * 查询当前经销商的个人信息
	 */
	@Override
	public AgencyInfoVo selectAgencyInfo(Long id, Long facId, Long ageId) {
		return agencyInfoMapper.selectAgencyInfo(id, facId, ageId);
	}
	
	/**
	 * 保存当前经销商的公司信息
	 */
	@Override
	@Transactional
	public boolean saveCompanyInfo(AgencyInfoCompanyVo agencyCompVo) {
		
		return agencyInfoMapper.saveAgencyCompanyInfo(agencyCompVo)>0 ? true : false;
	}

	/**
	 * 保存当前经销商的个人信息
	 */
	@Override
	@Transactional
	public boolean saveAgencyInfo(AgencyInfoVo agencyUserVo) {
		
		return agencyUserMapper.updateByVo(agencyUserVo)>0 ? true : false ;
	
	}

	/**
	 * 查询经销商的公司信息
	 */
	@Override
	public AgencyInfoCompanyVo selectCompanyInfo(Long facId, Long ageId) {
		
		return agencyInfoMapper.selectCompanyInfo(facId, ageId);
	}



	

	



}
